package com.by.user.controller;

import com.by.rpc.annotation.*;
import com.by.user.api.service.IUserService;
import com.by.user.api.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * 用户RPC控制器
 * 专门用于处理来自网关的RPC调用
 */
@Service
@ApiEndpoint(serviceName = "user-service", version = "1.0.0", group = "default")
public class UserRpcController {

    @Autowired
    @Qualifier("userServiceImpl")
    private IUserService userService;

    @RpcMethod(value = "/user/register", method = "POST")
    public UserVo register(@RpcBody("username") String username, @RpcBody("password") String password) {
        return userService.register(username, password);
    }

    @RpcMethod(value = "/user/login", method = "POST")
    public UserVo login(@RpcBody("username") String username, @RpcBody("password") String password) {
        return userService.login(username, password);
    }

    @RpcMethod(value = "/user/{id}", method = "GET")
    public UserVo getUserById(@RpcPath("id") Long id) {
        return userService.getUserById(id);
    }
}